var addMenu={
    isMenuName:function () {
        var menuName=$.trim($("#menuName").val());
        if(null == menuName || "" == menuName || undefined == menuName){
            layer.msg("菜单名称不能为空",{icon:0});
        }else {
            $.ajax({
                url: application.contextPath + "/menu/queryIsNameRep",
                type: 'GET',
                dataType: 'json',
                data:{
                    menuName:menuName
                },
                success: function (res) {
                    if('0'!=res.data){
                        layer.msg("菜单名称已存在",{icon:5});
                    }
                },
                error: function (data) {
                    layer.msg("网络异常，请稍后再试",{icon:5});
                }
            })
        }
    },
    commitAdd:function () {
        var data = {};
        data.parentId="0";
        if(menuId !=undefined && "" != menuId && null != menuId){
            data.parentId=menuId;
        }
        data.menuName=$.trim($("#menuName").val());
        data.menuType=$("#menuType option:selected").val();
        data.menuIcon=$("#menuIcon option:selected").val();
        data.menuUrl=$.trim($("#menuUrl").val());
        if(null == menuName || "" == menuName || undefined == menuName){
            layer.msg("菜单名称不能为空",{icon:0});
        }else {
            $.ajax({
                url: application.contextPath + "/menu/queryIsNameRep",
                type: 'GET',
                dataType: 'json',
                data:{
                    menuName:data.menuName
                },
                success: function (res) {
                    if('0'!=res.data){
                        layer.msg("菜单名称已存在",{icon:5});
                    }else{
                        $.ajax({
                            url: application.contextPath+"/menu/addMenu",
                            type:"POST",
                            contentType: "application/json; charset=utf-8",
                            dataType:"json",
                            data:JSON.stringify({parmsMap:data}),
                            success:function (res) {
                                if("1" == res.data){
                                    loadUtil.load({
                                        container:'#homeContent',
                                        url: application.contextPath+"/menu/showMenuPage?menuId=5"
                                    });
                                }
                            }
                        });
                    }
                },
                error: function (data) {
                    layer.msg("网络异常，请稍后再试",{icon:5});
                }
            });
        }
        return false;
    }
};

$(document).ready(function(){
    $("#cancel").click(function(){
        loadUtil = new Load($);
        loadUtil.load({
            container:'#homeContent',
            url: application.contextPath+"/menu/showMenuPage?menuId=5"
        });
        return false;
    });
});